package com.plant.serviceImpl;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.plant.dao.BaseDao;
import com.plant.entity.UgcComplaint;
import com.plant.entity.UgcFaq;
import com.plant.entity.UgcFaqAnswer;
import com.plant.entity.UgcFeedback;
import com.plant.entity.UgcNewthings;
import com.plant.entity.UgcTopicJoin;
import com.plant.entity.UgcUploadImages;
import com.plant.service.NewThingsService;


@Service
@Transactional
public class NewThingsServiceImpl implements NewThingsService {
	
	@Resource(name="baseDaoImpl")
	private BaseDao basedao;
	
	public boolean addnewthings(UgcNewthings th) {  //----1.添加发布新鲜事
		return basedao.add(th);
	}

	public Object onenewthings(UgcNewthings th) {    //---2.查找返回一个新鲜事对象
		return null;
	}
	
	public boolean addnewthingsurl(UgcUploadImages upi) {//3.添加新鲜事图片地址
		return basedao.add(upi);
	}

	public boolean deleteNewThings(UgcNewthings uth) {  //---4.用户删除新鲜事
		return basedao.del(uth);
	}

	public boolean delNewThingphoto(UgcNewthings uth) {//---5.用户删除新鲜事图片
		boolean b=true;
		String hql="delete from UgcUploadImages where fromContentId=("+uth.getId()+") and fromContentType=1";//---1.删除用户发布图片
		b=basedao.updatehql(hql);
		String hql2="delete from UgcComment where toContentType=1 and toContentId=("+uth.getId()+")";    //----2.删除评论  
		b=basedao.updatehql(hql2);
		String hql3="delete from UgcLike where toContentType=1 and toContentId=("+uth.getId()+")";       //---3.删除点赞
		b=basedao.updatehql(hql3);
		return b;
	}

	public boolean delfaq(UgcFaq ufq) {//  ----6.删除求助内容
		return basedao.del(ufq);
	}

	public boolean delfaqphoto(UgcFaq ufq) {//7,删除求助图片
		boolean Succ=true;
		String hql2="delete from UgcUploadImages where fromContentType=3 and fromContentId=("+ufq.getId()+")";   //---删除求助图片
		Succ=basedao.updatehql(hql2);
		String hql="delete from UgcFaqAnswer where toFaqId=("+ufq.getId()+")";   //---删除回答图片
		Succ=basedao.updatehql(hql);
		return Succ;
	}

	
	public boolean delfaqAnswer(UgcFaqAnswer ufaA) {//---8.删除求助回答
		return basedao.del(ufaA);
	}
	

	public boolean delMyAnswerphoto(UgcFaqAnswer ufaA) {
		boolean Succ=true;
		String hql2="delete from UgcUploadImages where fromContentType=5 and fromContentId=("+ufaA.getId()+")"; //-10.删除我的回答图片 
		Succ=basedao.updatehql(hql2);
		return Succ;
	}
	
	public boolean delTopicJoin(UgcTopicJoin utj) { //---9.删除话题参与
		boolean Succ=true;
		Succ=basedao.del(utj);
		String hql="delete from UgcUploadImages where fromContentType=4 and fromContentId=("+utj.getId()+")";
		Succ=basedao.updatehql(hql);
		return Succ;
	}

	
	public boolean AddFeedBack(UgcFeedback ufb) {  //---11，添加反馈信息
		return basedao.add(ufb);
	}

	
	public boolean AddComplaint(UgcComplaint ucp) { //---12..添加投诉
		return basedao.add(ucp);
	}

	public boolean AddTopicJoin(UgcTopicJoin utj) {//添加话题参与
		return basedao.add(utj);
	}
	

}
